define(function(require, exports, module) {
	var $ = require('jquery')
	require('jquery.tmpl')
	var Spine = require('spine')
	var LocationItem = Spine.Controller.sub({
		events: {
			'click': 'open'
		},
		init: function() {
			App.bind('open', this.proxy(function(file) {
				if (this.model.path.length >= file.path.length && this.model.path.indexOf(file.path) >= 0) {
					this.model.destroy({
						ajax: false
					})
				}
			}))
			this.model.bind('destroy', this.release)
		},
		render: function() {
			this.replace($("#locationTemplate").tmpl(this.model))
			return this
		},
		isCurrentLocation: function() {
			return $('#browser-location a').last().is(this.el) ? true : false
		},
		open: function(event) {
			event.preventDefault()
			if (this.isCurrentLocation()) {} else {
				App.trigger('open', {
					'name': this.model.name,
					'type': 'folder',
					'path': this.model.path
				})
			}
		}
	})
	module.exports = LocationItem
	var App = require('./app')
})